function order() {
  if (app.documents.length > 0) {
    var elementsSelected = app.activeDocument.selection;
    if (elementsSelected.length > 0) {
      // 排序
      for (i = 0; i < elementsSelected.length; i++) {
        for (j = 0; j < elementsSelected.length - 1 - i; j++) {
          if (
            parseInt(elementsSelected[j].name) <
            parseInt(elementsSelected[j + 1].name)
          ) {
            var temp = elementsSelected[j];
            elementsSelected[j] = elementsSelected[j + 1];
            elementsSelected[j + 1] = temp;
          }
        }
      }
      // 创建排序后的元素
      for (k = 0; k < elementsSelected.length; k++) {
        elementsSelected[k].selected = false;
        elementsSelected[k].duplicate(
          elementsSelected[k].parent,
          elementsSelected.PLACEATEND
        );
      }
      // 删除原有项
      for (n = 0; n < elementsSelected.length; n++) {
        elementsSelected[n].remove();
      }
    } else {
      alert("请先选中需要排序的物体!");
    }
  } else {
    alert("请先打开一个文档!");
  }
}
